package com.example.myapplication.tack_07.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_06.BooksXQ;
import com.example.myapplication.tack_06.data.BooksListData;
import com.example.myapplication.tack_07.ThreeActivity;
import com.example.myapplication.tack_07.Youth;
import com.example.myapplication.tack_07.data.BannerData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class ThreeAdapter extends RecyclerView.Adapter<ThreeAdapter.My> {
    private List<BannerData.DataDTO> list;
    private Context context;
    private View view;

    public ThreeAdapter(List<BannerData.DataDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.theme,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        Glide.with(context).load(OkHttpTool.URL+list.get(position).getImgUrl()).into(holder.imags);
        holder.name.setText(list.get(position).getName());
        holder.imags.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int id1 = list.get(position).getId();
                Intent intent = new Intent(context, ThreeActivity.class);
                intent.putExtra(Common.COMMON,String.valueOf(id1));
                context.startActivity(intent);

            }
        });
    }

    @Override
    public int getItemCount() {
        return list != null?list.size():0;
    }

    public class My extends RecyclerView.ViewHolder{
        private ImageView imags;
        private TextView name;

        public My(@NonNull View itemView) {
            super(itemView);
            imags = view.findViewById(R.id.imags);
            name = view.findViewById(R.id.text);

        }
    }
}
